<?php
/**
 * 返回数据.
 */
require_once './response.php';
require_once './db.php';
require_once './file.php';
$page = isset($_GET['page']) ? $_GET['page'] : 1;
$pageSize = isset($_GET['pagesize']) ? $_GET['pageSize'] : 2;
if (!is_numeric($page) || !is_numeric($pageSize)) {
    return Response::show(401, '数据不合法');
}
$offset = ($page - 1) * $pageSize;
$sql = 'select * from sfk_father_module where status=1 order by sort desc limit '.$offset.','.$pageSize;
$cache = new File();
$videos = array();
if (!$cache->cacheData('index_mk_cache'.$page.'-'.$pageSize)) {
    try {
        $connect = Db::getInstance()->connect();
    } catch (Exception $e) {
        return Response::show(403, '数据库连接失败');
    }
}
$result = mysql_query($sql, $connect);

while ($video = mysql_fetch_assoc($result)) {
    $videos[] = $video;
}

if ($videos) {
    $cache->cacheData('index_mk_cache'.$page.'-'.$pageSize, $videos, 1200);
}

if ($videos) {
    return Response::show(200, '首页数据获取成功', $videos);
} else {
    return Response::show(401, '获取数据失败', $videos);
}
